package com.buaa.divinationmaster.database;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.TypeConverters;
import android.content.Context;

import com.buaa.divinationmaster.database.dao.DivinationRecordDao;
import com.buaa.divinationmaster.database.dao.TarotCardDao;
import com.buaa.divinationmaster.database.entity.DivinationRecordEntity;
import com.buaa.divinationmaster.database.entity.TarotCardEntity;

/**
 * Room数据库配置
 * 根据需求文档实现完整的数据库架构
 */
@Database(
    entities = {
        DivinationRecordEntity.class,
        TarotCardEntity.class
    },
    version = 1,
    exportSchema = false
)
@TypeConverters({Converters.class})
public abstract class DivinationDatabase extends RoomDatabase {
    
    private static final String DATABASE_NAME = "divination_master.db";
    private static volatile DivinationDatabase INSTANCE;
    
    public abstract DivinationRecordDao divinationRecordDao();
    public abstract TarotCardDao tarotCardDao();
    
    public static DivinationDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (DivinationDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(
                        context.getApplicationContext(),
                        DivinationDatabase.class,
                        DATABASE_NAME
                    )
                    .fallbackToDestructiveMigration()
                    .build();
                }
            }
        }
        return INSTANCE;
    }
    
}
